
package trees.tree

abstract class AbstractNode(children:List[AbstractLeaf],treeStart:Int,treeEnd:Int,idStart:Int,
                            idEnd:Int)extends AbstractLeaf(IdFactory.getID("node")){

    def equals(b:AbstractLeaf,treeA:List[Int],treeB:List[Int]):Boolean = {
        def check(a:List[Int],b:List[Int]):Boolean={
            if(a.size==0){
                true
            }else{
                if(a(0)==b(0)){
                    check(a drop 1, b drop 1)
                }else{
                    false
                }
            }
        }
        b match{
            case l:Leaf => false
            case n:ImmutableNode =>
                var same:Boolean= (this.treeEnd-this.treeStart)==(n.treeEnd-n.treeStart)&&(this.treeEnd-this.treeStart)==(n.idEnd-n.idStart)
                if(same){
                    check(treeA.slice(this.treeStart,this.treeEnd),treeB.slice(n.treeStart,n.treeEnd))
                }else{
                    false
                }
            case n:MutableNode =>
                var same:Boolean= (this.treeEnd-this.treeStart)==(n.treeEnd-n.treeStart)&&(this.treeEnd-this.treeStart)==(n.idEnd-n.idStart)
                if(same){
                    check(treeA.slice(this.treeStart,this.treeEnd),treeB.slice(n.treeStart,n.treeEnd))
                }else{
                    false
                }
        }
    }
}
